<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>购物车</title>
    <link rel="stylesheet" type="text/css" href="css/base.css"/>
    <link rel="stylesheet" type="text/css" href="css/shopcar.css"/>
    <link rel="stylesheet" type="text/css" href="css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/loaders.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/loading.css"/>
    <link rel="stylesheet" type="text/css" href="sourse/layer/mobile/need/layer.css">
    <script src="js/rem.js"></script>
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="sourse/layer/mobile/layer.js"></script>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>

    <script src="/js/common.js"></script>
    <script type="text/javascript">

        $(window).load(function () {
            $(".loading").addClass("loader-chanage")
            $(".loading").fadeOut(300)
        })

    </script>


</head>
<!--loading页开始-->
<div class="loading">
    <div class="loader">
        <div class="loader-inner pacman">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</div>
<!--loading页结束-->
<body>
<!--头部-->
<header class="mui-bar mui-bar-nav" id="header">
    <a class="btn" href="javascript:history.go(-1)">
        <i class="iconfont icon-fanhui"></i>
    </a>
    <h4>购物车</h4>
</header>
<!--header end-->

<div class="warp warptwo clearfloat">
    <div class="shopcar clearfloat" render-loop="list">


        <div class="list clearfloat fl">
            <div class="xuan clearfloat fl">
                <div class="radio">
                    <label>
                        <input type="checkbox" name="sex" value=""/>
                    </label>
                </div>
            </div>
            <a href="javascript:void(0)">
                <div class="tu clearfloat fl">
                    <span></span>
                    <img render-src="list.goods.imgUrl"/>
                </div>
                <div class="right clearfloat fl">
                    <p class="tit over" render-html="list.goods.title">单反相机，彰显你的风格</p>
                    <p class="jifen over" render-html="list.goods.integral">100000积分</p>
                    <div class="bottom clearfloat">

                        <div class="zuo clearfloat fl">
                            <ul>
                                <li><img src="images/jian.jpg"/></li>
                                <li render-html="list.count">1</li>
                                <li><img src="images/jia.jpg"/></li>
                            </ul>
                        </div>
                        <i class="iconfont icon-lajixiang fr" render-attr="">
                        </i>

                    </div>
                </div>
            </a>
        </div>


    </div>
</div>

<!--结算栏-->
<div class="settlement clearfloat">
    <div class="zuo clearfloat fl box-s" >
        合计：<span id="zongji"></span>
    </div>
    <a href="#" class="fl db" id="jiesuan">
        立即结算
    </a>
</div>
<!--settlement end-->

<!--f导航栏-->
<footer class="page-footer fixed-footer" id="footer">
    <ul>
        <li>
            <a href="index.html">
                <i class="iconfont icon-shouye"></i>
                <p>首页</p>
            </a>
        </li>

        <li>
            <a href="cation.html">
                <i class="iconfont icon-icon04"></i>
                <p>分类</p>
            </a>
        </li>

        <li class="active">
            <a href="shopcar.html">
                <i class="iconfont icon-gouwuche"></i>
                <p>购物车</p>
            </a>
        </li>
        <li>
            <a href="/game/game.html">
                <i class="iconfont icon-yonghuming"></i>
                <p>商城小游戏</p>
            </a>
        </li>
    </ul>
</footer>
<!--footer end-->

<script type="text/javascript">

    var arr = []

    var id = getUser().id

    $.get("/shopcars", {userId: id}, function (data) {

        $(".warptwo").renderValues({list: data}
        /*, {
            handle: function (ele, value) {
                console.log(value);
                ele.href ="312312"
            }
        }*/)
    })


                   setTimeout(function () {

                    $('input[type="checkbox"]').click(function () { // 找到勾选按钮，绑定事件
                        tatol();
                    });
                }, 300)


                setTimeout(function () {

                    $('.list ul img').click(function () { // 找到加减按钮，绑定点击事件
                        var val = $(this).parent().parent().children().eq(1);
                        if ($(this).parent().index()) {
                            val.html(parseInt(val.html()) + 1);
                        } else {
                            val.html(val.html() > 1 ? parseInt(val.html()) - 1 : 1);
                        }
                        tatol();
                    });
                }, 300)


    setTimeout(function () {

        $('.icon-lajixiang').click(function () { // 找到删除按钮，绑定点击事件



            var self = this;
            layer.open({
                content: '确定删除？',
                btn: ['确定', '取消'],
                yes: function (index) {
                     $(self).parent().parent().parent().parent().remove();
                     layer.closeAll();
                     tatol();
                    /*$.ajax({
                        type: "DELETE",
                        url: "/shopcars/delete",
                        success: function (data) {
                            //退出登录后,清除缓存数据,刷新主界面
                            location.reload()
                        }
                    });*/
                }
            });

        });
    }, 300)


    var tatol = function () { // 计算总积分
        var count = 0;
        $('.list').map(function (index, item) {
            var $el = $(item);
            if ($el.find('input[type="checkbox"]').is(":checked")) {
                count += parseFloat($el.find('.jifen').html()) * parseInt($el.find('.zuo li').eq(1).html());
            }
        });
        if (count > 0) {
            $('.settlement span').html(count);
        }
    }


    $(function () {
        $("#jiesuan").click(function () {
            console.log($("#zongji").html());
            $("#jiesuan").attr("href", "confirm.html?count=" + $("#zongji").html())
        })
    })
</script>

</body>

</html>
